import { useState, useEffect } from 'react';

interface DemoModel {
  num: number;
  setNum: React.Dispatch<React.SetStateAction<number>>;
  setNumAsync: () => void;
}

export default function demoModel(): DemoModel {
  const [num, setNum] = useState<number>(0);

  useEffect(() => {
    const timer = setTimeout(() => {
      setNum(10);
    }, 1000);
    return () => clearTimeout(timer);
  }, []);

  const setNumAsync = () => {
    setTimeout(() => {
      setNum((prevNum) => prevNum + 1);
    }, 1000);
  };

  return {
    num,
    setNum,
    setNumAsync,
  };
}
